﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Flame.Reflection
{
    class Namespace : Class
    {
        public Dictionary<string, Class> Childs { get; set; }
        public Namespace(string name)
            : base(name)
        {
            Childs = new Dictionary<string, Class>();
        }

        void _addClass(string s)
        {
            try
            {
                Childs.Add(s, new Class(s));
            }
            catch { }
        }

        Namespace _addNamespace(string s)
        {
            Namespace n;
            try
            {
                if (Childs.ContainsKey(s))
                {
                    n = Childs[s] as Namespace;
                }
                else
                {
                    n = new Namespace(s);
                    Childs.Add(s, n);
                }
            }
            catch { return null; }
            return n;
        }

        public void Add(string[] names)
        {
            if (names.Length == 1)
            {
                _addClass(names[0]);
            }
            else
            {
                Namespace n = _addNamespace(names[0]);
                if (n != null)
                    n.Add(names.Skip<string>(1).ToArray<string>());
            }
        }
    }

}
